package lesson03.TCP;

import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TCPPoolServer01 extends TCPEchoServer01 {

    public TCPPoolServer01(int port) throws IOException {
        super(port);
    }

    @Override
    public void start() throws IOException {
        System.out.println("服务器启动，等待客户端连接");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3,
                10,
                1,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1));

        while (true) {
            Socket Clinetaccept = socket.accept();
            threadPoolExecutor.submit(() -> {
                processConnection(Clinetaccept);
            });
        }
    }

    public static void main(String[] args) throws IOException {
        TCPPoolServer01 tcpPoolServer01 = new TCPPoolServer01(9090);
        tcpPoolServer01.start();
    }

}
